package com.pro.schedule.controller;

import com.pro.schedule.entity.EventType;
import com.pro.schedule.service.EventTypeService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
public class EventTypeController {
    @Resource
    EventTypeService eventTypeService;

    @ApiOperation("获取事件类型")
    @PostMapping("/schedule/eventType/getList")
    public List<EventType> getEventTypeList(HttpServletRequest request) {
        String token = request.getHeader("Authorization");
        return eventTypeService.getEventTypeList(token);
    }

    @ApiOperation("保存或修改事件类型")
    @PostMapping("/schedule/eventType/saveOrUpdate")
    public String saveOrUpdateEventType(@RequestBody EventType eventType, HttpServletRequest request) throws Exception {
        String token = request.getHeader("Authorization");
        return eventTypeService.saveOrUpdateEventType(token, eventType);
    }

    @ApiOperation("删除指定事件类型")
    @PostMapping("/schedule/eventType/delete")
    public String deleteEventType(@RequestBody EventType eventType) throws Exception {
        return eventTypeService.deleteEventType(eventType.getEventTypeId());
    }

}
